********************************************************************************
* Leipziger, L, Aarslew, L, & M. Christensen
* Replication Code for "Do Group-Based Inequalities Feel More Unjust?"
* POQ, 2026
* This code: Fig 3: Effects of interpersonal and intergroup treatments on emotions
********************************************************************************
********************************************************************************
clear all
frame rename default data

*** Panel A: Anger
** Combining datasets 
use "data/IN_data_clean.dta", clear
append using "data/ZA_data_clean.dta"
append using "data/US_data_clean.dta"

lab define country_lab 1 "India" 2 "\forceindent South Africa" 3 "\forceindent US"
lab values country country_lab

**treatments
gen treat=0 if D==1
replace treat=1 if D==2

lab define treat_lb 0 "\forceindent Interpersonal ineq." 1 "\forceindent Intergroup ineq."
lab values treat treat_lb


** Marginal effects (all)
qui reg angry_std i.treat i.country, rob
mat A = r(table)
est store angry_all // for tables
estadd scalar ajr2 = e(r2_a)

** Marginal effects (India): 
qui reg angry_std i.treat if country==1, rob
mat B = r(table)
est store angry_india // for tables
estadd scalar ajr2 = e(r2_a)

** Marginal effects (South Africa)
qui reg angry_std i.treat if country==2, rob

mat C = r(table)
est store angry_za // for tables
estadd scalar ajr2 = e(r2_a)

** Marginal effects (USA)
qui reg angry_std i.treat if country==3, rob
mat D = r(table)
est store angry_us // for tables
estadd scalar ajr2 = e(r2_a)

*making table SM5
esttab angry_all angry_india angry_za angry_us using "output/tableSM5.tex", lab nogap wide tex cells("b(fmt(3))" se(par(`"("' `")"') fmt(3)) p(par(`"["' `"]"') fmt(3))) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(%9.3f) ///
	noobs nonotes nonumbers  ///
	stats(ajr2  N, labels("Adjusted R^2" "N") fmt(3 0)) varlabels(_cons Constant) mtitles("Pooled" "India" ///
	"South Africa" "US") replace
	
	

* Matrix 
mat E = 1,1,A[1,2],A[5,2],A[6,2]\			/// 
		1,2,B[1,2],B[5,2],B[6,2]\			/// 
		1,3,C[1,2],C[5,2],C[6,2]\			/// 
		1,4,D[1,2],D[5,2],D[6,2]
		
mat list E	


frame create plot1
cwf plot1		
svmat E
rename E1 treatment						// 1 = Intergroup
rename E2 Xpos							// Position on X-axis
rename E3 b								// Parameter estimate (Marginal effect)
rename E4 ll							// lower confidence level
rename E5 ul							// upper confidence level


* Plot Panel A in Figure 3: 
tw ///
	(rspike ll ul Xpos if treatment == 1, lc(black)) ///
	(scatter b Xpos if treatment == 1, msym(O) mc(black) msize(med)) ///
	, yscale(range(-0.15 0.5) extend lc(none)) ytit("Feelings of Anger (sd)") ///
	yline(0) ylab(-0.4 -0.2 0 0.2 0.4, labsize(small) gstyle(solid) glc(gs15%30) notick) ///
	xscale(range(.5 4.7) extend) xtit("Country") ///
	xlab(1 "Pooled" 2 "India" 3 `" "South" "Africa" "' 4  `" "United" "States" "'  , labsize(small) gstyle(solid) glc(gs15%30) notick) ///
	legend(off) ///
	plotregion(lcolor(black) lwidth(medium)) ///
	scale(1.3) graphregion(m(small)) ///
	tit("{bf:(A)} Effects on Anger", pos(11) justification(left) size(med)) ///
	name(griev_anger, replace)
	

	
	
	
*** Panel B: Frustration
** Combining datasets 
use "data/IN_data_clean.dta", clear
append using "data/ZA_data_clean.dta"
append using "data/US_data_clean.dta"

lab define country_lab 1 "India" 2 "\forceindent South Africa" 3 "\forceindent US"
lab values country country_lab

**treatments
gen treat=0 if D==1
replace treat=1 if D==2

lab define treat_lb 0 "\forceindent Interpersonal ineq." 1 "\forceindent Intergroup ineq."
lab values treat treat_lb


** Marginal effects (all)
qui reg frustrated_std i.treat i.country, r
mat A = r(table)
est store frustration_all // for tables
estadd scalar ajr2 = e(r2_a)

** Marginal effects (India): 
qui reg frustrated_std i.treat if country==1, rob
mat B = r(table)
est store frustration_india // for tables
estadd scalar ajr2 = e(r2_a)

** Marginal effects (South Africa)
qui reg frustrated_std i.treat if country==2, rob

mat C = r(table)
est store frustration_za // for tables
estadd scalar ajr2 = e(r2_a)

** Marginal effects (USA)
qui reg frustrated_std i.treat if country==3, rob
mat D = r(table)
est store frustration_us // for tables
estadd scalar ajr2 = e(r2_a)

*making table A6
esttab frustration_all frustration_india frustration_za frustration_us using "output/tableSM6.tex", lab nogap wide tex cells("b(fmt(3))" se(par(`"("' `")"') fmt(3)) p(par(`"["' `"]"') fmt(3))) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(%9.3f) ///
	noobs nonotes nonumbers  ///
	stats(ajr2  N, labels("Adjusted R^2" "N") fmt(3 0)) varlabels(_cons Constant) mtitles("Pooled" "India" ///
	"South Africa" "US") replace
	
	

* Matrix 
mat E = 1,1,A[1,2],A[5,2],A[6,2]\			/// 
		1,2,B[1,2],B[5,2],B[6,2]\			/// 
		1,3,C[1,2],C[5,2],C[6,2]\			/// 
		1,4,D[1,2],D[5,2],D[6,2]
		
mat list E	


frame create plot2
cwf plot2
svmat E
rename E1 treatment						// 1 = Intergroup
rename E2 Xpos							// Position on X-axis
rename E3 b								// Parameter estimate (Marginal effect)
rename E4 ll							// lower confidence level
rename E5 ul							// upper confidence level


* Plot Panel B in Figure 3: 
tw ///
	(rspike ll ul Xpos if treatment == 1, lc(black)) ///
	(scatter b Xpos if treatment == 1, msym(O) mc(black) msize(med)) ///
	, yscale(range(-0.5 0.5) extend lc(none)) ytit("Feelings of Frustration (sd)") ///
	yline(0) ylab(-0.4 -0.2 0 0.2 0.4, labsize(small) gstyle(solid) glc(gs15%30) notick) ///
	xscale(range(.5 4.7) extend) xtit("Country") ///
	xlab(1 "Pooled" 2 "India" 3 `" "South" "Africa" "' 4  `" "United" "States" "' , labsize(small) gstyle(solid) glc(gs15%30) notick) ///
	legend(off) ///
	plotregion(lcolor(black) lwidth(medium)) ///
	scale(1.3) graphregion(m(small)) ///
	tit("{bf:(B)} Effects on Frustration", pos(11) justification(left) size(med)) ///
	name(griev_frustation, replace)
	

* Combine Panels A and B:
graph combine griev_anger griev_frustation, cols(2)
graph display, xsize(14) ysize(6) scale(1.3)
graph export "output/figure3.pdf", as(pdf) replace
